package com.matrix.gallery.ui.wallpaper.fragment

import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager.LayoutParams
import androidx.fragment.app.DialogFragment
import com.blankj.utilcode.util.ToastUtils
import com.matrix.gallery.databinding.DialogDownloadFragmentBinding


class DownloadFragmentDialog(clickListener: OnClickListener) : DialogFragment() {

    private lateinit var mViewBinding: DialogDownloadFragmentBinding
    private var mClickListener: OnClickListener = clickListener

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mViewBinding = DialogDownloadFragmentBinding.inflate(layoutInflater)
        initView()
        initData()
        initListener()
        return mViewBinding.root
    }

    private fun initView() {

    }

    private fun initData() {

    }

    private fun initListener() {
        mViewBinding.tvDown.setOnClickListener {
            mClickListener.onClick(1)
            dialog!!.dismiss()
        }
        mViewBinding.tvShareToWechat.setOnClickListener {
            mClickListener.onClick(2)
            dialog!!.dismiss()
        }
        mViewBinding.tvShareNet.setOnClickListener {
            mClickListener.onClick(3)
            dialog!!.dismiss()
        }
        mViewBinding.tvCancel.setOnClickListener {
            dialog!!.dismiss()
        }
    }

    interface OnClickListener {
        fun onClick(position: Int)
    }

    override fun onStart() {
        super.onStart()
        val window = dialog!!.window
        if (window != null) {
            val layoutParams = window.attributes
            layoutParams.width = LayoutParams.MATCH_PARENT
            layoutParams.height = LayoutParams.WRAP_CONTENT
            layoutParams.gravity = Gravity.BOTTOM
            window.attributes = layoutParams
        }
    }
}